/*
 * @Author: zi.yang
 * @Date: 2020-06-17 23:35:05
 * @LastEditTime: 2021-09-28 23:46:04
 * @LastEditors: zi.yang
 * @Description: 数据库连接池
 * @FilePath: \project-management\models\db.js
 */

const Sequelize = require('sequelize');
const {
  database,
  username,
  password,
  host,
  port,
} = require('../config/db.config');

//初始化链接（连接池）
const sequelize = new Sequelize(database, username, password, {
  host,
  port,
  dialect: 'mysql',
  dialectOptions: {
    charset: 'utf8',
    supportBigNumbers: true,
    bigNumberStrings: true,
  },
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000,
  },
  timezone: '+08:00',
});

//验证是否连接成功
sequelize
  .authenticate()
  .then(() => {
    console.log('Database Connection Succeeded.');
  })
  .catch((err) => {
    console.error('Database Connection Failed.', err);
  });

module.exports = sequelize;
